package com.app.util;

import org.springframework.http.HttpStatus;

/**
 * @Description: 错误信息枚举
 * @Author: Rujh
 * @Date: 2022/10/18 17:26
 */
public enum ErrorCode {
    ACCESS_DENIED(HttpStatus.FORBIDDEN, "ACCESS_DENIED", "访问被拒绝"),
    USER_NOT_LOGIN(HttpStatus.UNAUTHORIZED, "USER_NOT_LOGIN", "用户未登录"),
    DOMAIN_READ_FAIL(HttpStatus.INTERNAL_SERVER_ERROR, "DOMAIN_READ_FAIL", "域名读取失败"),
    TENANT_NOT_EXIST(HttpStatus.NOT_FOUND, "TENANT_NOT_EXIST", "租户信息不存在"),
    APPID_NOT_EXIST(HttpStatus.NOT_FOUND, "APPID_NOT_EXIST", "应用ID不存在"),
    DATA_NOT_EXIST(HttpStatus.NOT_FOUND, "DATA_NOT_EXIST", "数据不存在"),
    FILE_READ_FAIL(HttpStatus.INTERNAL_SERVER_ERROR, "FILE_READ_FAIL", "文件读取失败"),
    BAD_REQUEST(HttpStatus.BAD_REQUEST, "BAD_REQUEST", "参数错误:%s"),
    REQUIRE_ARGUMENT(HttpStatus.BAD_REQUEST, "REQUIRE_ARGUMENT", "缺少参数:%s"),
    REQUIRE_ARGUMENT_AT_LEAST(HttpStatus.BAD_REQUEST, "REQUIRE_ARGUMENT_AT_LEAST", "参数%s至少要有%s个"),
    INVALID_ARGUMENT(HttpStatus.BAD_REQUEST, "INVALID_ARGUMENT", "非法参数:%s"),
    DUPLICATE_ARGUMENT(HttpStatus.BAD_REQUEST, "DUPLICATE_ARGUMENT", "参数重复:%s"),
    INVALID_QUERY(HttpStatus.BAD_REQUEST, "INVALID_QUERY", "%s非法查询参数"),
    QUERY_FIELD_REQUIRE(HttpStatus.BAD_REQUEST, "QUERY_FIELD_REQUIRE", "缺少查询参数:%s"),
    FIELD_NOT_FOUND(HttpStatus.BAD_REQUEST, "FIELD_NOT_FOUND", "%s字段不存在"),
    INVALID_QUERY_FORMAT(HttpStatus.BAD_REQUEST, "INVALID_QUERY_FORMAT", "%s参数格式不正确"),
    QUERY_FIELD_INVALID(HttpStatus.BAD_REQUEST, "QUERY_FIELD_INVALID", "查询参数错误:%s"),
    INVALID_RANG(HttpStatus.BAD_REQUEST, "INVALID_RANG", "%s不能大于%s"),
    EMPTY_ROLES_NOT_ALLOWED(HttpStatus.BAD_REQUEST, "EMPTY_ROLES_NOT_ALLOWED", "角色不能为空"),
    USER_HAS_NO_AUTHORITY(HttpStatus.BAD_REQUEST, "USER_HAS_NO_AUTHORITY", "用户没有权限"),
    ONLY_ADMIN_ALLOWED(HttpStatus.BAD_REQUEST, "ONLY_ADMIN_ALLOWED", "没有管理员权限"),
    NO_ROLE_AUTHORITY(HttpStatus.BAD_REQUEST, "NO_ROLE_AUTHORITY", "没有该角色的查看权限"),
    NO_USER_AUTHORITY(HttpStatus.BAD_REQUEST, "NO_USER_AUTHORITY", "没有该用户的查看权限"),
    INVALID_ACCESS_KEY(HttpStatus.BAD_REQUEST, "INVALID_ACCESS_KEY", "非法AccessKey"),
    SERVICE_UNAVAILABLE(HttpStatus.SERVICE_UNAVAILABLE, "SERVICE_UNAVAILABLE", "服务不可用"),
    INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "INTERNAL_SERVER_ERROR", "内部服务错误"),
    NO_AGREEMENT(HttpStatus.BAD_REQUEST, "NO_AGREEMENT", "未同意服务条款"),
    INVALID_PACKAGE(HttpStatus.BAD_REQUEST, "INVALID_PACKAGE", "包名格式错误"),
    INVALID_APPNAME(HttpStatus.BAD_REQUEST, "INVALID_APPNAME", "应用名称格式错误"),
    INVALID_HASH(HttpStatus.BAD_REQUEST, "INVALID_HASH", "HASH格式错误"),
    PACKAGE_REPEAT(HttpStatus.BAD_REQUEST, "PACKAGE_REPEAT", "应用包重复"),
    INVALID_MESSAGE(HttpStatus.BAD_REQUEST, "INVALID_MESSAGE", "消息不可用"),
    ONE_NUMBER_LIMIT(HttpStatus.BAD_REQUEST, "ONE_NUMBER_LIMIT", "未授权用户只允许创建一个应用"),
    AES_ENCRYPTION_ERROR(HttpStatus.BAD_REQUEST, "AES_ENCRYPTION_ERROR", "AES加密错误"),
    DB_CONNECT_INVALID(HttpStatus.BAD_REQUEST, "DB_CONNECT_INVALID", "[exception: %s]无效的链接");

    private HttpStatus httpStatus;
    private String code;
    private String message;
    private static final String PCC_CODE_PREFIX = "API/";

    private ErrorCode(HttpStatus httpStatus, String code, String message) {
        this.setHttpStatus(httpStatus);
        this.setCode(code);
        this.setMessage(message);
    }

    public HttpStatus getHttpStatus() {
        return this.httpStatus;
    }

    private void setHttpStatus(HttpStatus httpStatus) {
        this.setPHttpStatus(httpStatus);
    }

    private void setPHttpStatus(HttpStatus httpStatus) {
        this.httpStatus = httpStatus;
    }

    public String getCode() {
        return "API/" + this.code;
    }

    private void setCode(String code) {
        this.setPCode(code);
    }

    private void setPCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return this.message;
    }

    private void setMessage(String message) {
        this.setPMessage(message);
    }

    private void setPMessage(String message) {
        this.message = message;
    }
}
